using System.Threading;
using System.Xml;
using MessageGateway;

namespace Delay
{
	public class DelayComponent : SimpleFilter
	{
        int delayMillis;

		public DelayComponent(IMessageReceiver input, IMessageSender output, int delayMillis)
            : base (input, output)
		{
            this.delayMillis = delayMillis;
		}

        public DelayComponent(string inputQueue, string outputQueue, int delayMillis, IMessageGatewayFactory factory)
            : this (factory.GetReceiverInstance(inputQueue), factory.GetSenderInstance(outputQueue), delayMillis)
        { }

        protected override void OnMessage(XmlDocument message)
        {
            Thread.Sleep(delayMillis);
            base.OnMessage(message);
        }
	}
}
